﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Happy.ExtentionMethods.Reflection;

namespace Happy.Event.Internal
{
    internal sealed class EventPublishContext : IEventPublishContext
    {
        private EventInterceptorChain _eventInterceptorChain;

        internal EventPublishContext(IEventPublisher eventPublisher, object @event, Action subscribersExecutor)
        {
            this.Publisher = eventPublisher;
            this.Event = @event;
            _eventInterceptorChain = new EventInterceptorChain(
                this,
                @event.GetType().GetAttributes<EventInterceptorAttribute>(),
                subscribersExecutor);
        }


        public IEventPublisher Publisher
        {
            get;
            private set;
        }

        public object Event { get; private set; }

        public void ExecuteNext()
        {
            _eventInterceptorChain.ExecuteNext();
        }
    }
}
